package cn.com.self.apis.file.response;

import lombok.Data;

/**
 * 返回结果
 *
 * @author CRL
 * @date 2019年7月29日 下午2:30:07
 */
@Data
public class BaseResponse<T> {
    static final String SUCCESS_MESSAGE = "操作成功";
    static final String FAILURE_MESSAGE = "操作失败";

    private String code;

    private T data;

    private String msg;

    public static final BaseResponse<?> SUCCESS = success();

    public static final BaseResponse<?> FAILURE = failure();

    private static BaseResponse<?> success() {
        return new BaseResponse<>(BaseResponseStatus.OK, SUCCESS_MESSAGE);
    }

    private static BaseResponse<?> failure() {
        return new BaseResponse<>(BaseResponseStatus.FAILURE, FAILURE_MESSAGE);
    }

    public BaseResponse() {
        this.code = BaseResponseStatus.OK;
        this.msg = SUCCESS_MESSAGE;
    }

    public BaseResponse(T t) {
        this.code = BaseResponseStatus.OK;
        this.msg = SUCCESS_MESSAGE;
        this.data = t;
    }

    public BaseResponse(String code, T data) {
        this.code = code;
        this.data = data;
    }

    public BaseResponse(String code, String message) {
        this.code = code;
        this.msg = message;
    }


    public BaseResponse<T> code(String code) {
        this.code = code;
        return this;
    }

    public BaseResponse<T> msg(String message) {
        this.msg = message;
        return this;
    }

    public BaseResponse<T> data(T data) {
        this.data = data;
        return this;
    }

}